package com.xszx.business.controller.admin;

import com.xszx.server.dto.AjaxJson;
import com.xszx.server.dto.Page;
import com.xszx.server.entity.Chapter;
import com.xszx.server.service.ChapterService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/chapter")
@Api(tags = "课程大章管理")
public class ChapterController {
    @Resource
    private ChapterService chapterService;

    @PostMapping("/getAllChapters")
    public Page getAllChapters(@RequestBody Page page){
        return chapterService.getAllChapters(page);
    }

    @GetMapping("/getChapter")
    public AjaxJson getChapter(String id){
        return AjaxJson.success().put("chapters",chapterService.getChapter(id));
    }

    @PostMapping("/save")
    public AjaxJson save(@RequestBody Chapter chapter){
        return AjaxJson.success(chapterService.saveOrUpdate(chapter));
    }
    @GetMapping("/deleteChapter")
    public AjaxJson deleteChapter(String id){
        int result = chapterService.del(id);
        if(result>0){
            return AjaxJson.success("删除成功");
        }else{
            return AjaxJson.error("删除失败");
        }
    }
}
